<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\adminapi\controller\v1\car;


use app\adminapi\controller\AuthController;
use app\services\car\CarOrderRefundServices;
use think\facade\App;
use crmeb\services\app\MiniProgramService;
class CarOrderRefund extends AuthController
{
    public function __construct(App $app,CarOrderRefundServices $services)
    {
        parent::__construct($app);
        $this->services = $services;
    }

    /**
     * 列表
     * @return mixed
     */
    public function getList(){
        $where = $this->request->getMore([
            ['keyword',''],
            ['status',''],
            ['order_type',1]
        ]);
        $admin = $this->request->adminInfo();
        if($admin['store_id']) $where['place_id'] = $admin['store_id'];
        return app('json')->success($this->services->getList($where,true));
    }
    /**
     * 删除
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function delete(){
        $data = $this->request->getMore([
            ['id', 0],
        ]);
        if (!$data['id']) return app('json')->fail('参数错误');
        return app('json')->success($this->services->delRefund((int)$data['id']));
    }

    /**
     * 退款申请审核
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function auditRefund(){
        $data = $this->request->postMore([
            ['id',0],
            ['status',''],
            ['reason',''],
        ]);
        if(!$data['id']) return app('json')->fail('参数错误');
        if(!$data['status']) return app('json')->fail('请选择退款方式');
        if($data['status'] == -1){
            if(!$data['reason']) return app('json')->fail('请输入驳回原因');
        }
        $op_user = $this->request->adminInfo();
        $op_user['user_name'] = $op_user['real_name'];
        return app('json')->success($this->services->auditRefund($data,$op_user,3));
    }
}
